package com.threegroup.android3grouppersonality.ui.fragment;

import android.os.Bundle;

import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.android.material.tabs.TabLayout;
import com.threegroup.android3grouppersonality.R;
import com.threegroup.android3grouppersonality.adapter.MyFragmentAdapter;
import com.threegroup.android3grouppersonality.ui.fragment.fragementHome.FollowFragment;
import com.threegroup.android3grouppersonality.ui.fragment.fragementHome.LookForPerFragment;
import com.threegroup.android3grouppersonality.ui.fragment.fragementHome.MaFriendFragment;
import com.threegroup.android3grouppersonality.ui.fragment.fragementHome.MaPlayFragment;
import com.threegroup.android3grouppersonality.ui.fragment.fragementHome.RecommendFragment;

import java.util.ArrayList;
import java.util.List;


public class HomeFragment extends Fragment  {
    private Toolbar toolbar;
    private TabLayout tabLayout;
    private ViewPager viewPager;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
         View view =inflater.inflate(R.layout.fragment_home, container, false);

        tabLayout = view.findViewById(R.id.tabs);
        viewPager = (ViewPager)view.findViewById(R.id.viewpager);

        List<String> titleList = new ArrayList<>();
        titleList.add("推荐");
        titleList.add("关注");
        titleList.add("交友");
        titleList.add("寻人");
        titleList.add("约玩");

        tabLayout.setTabMode(TabLayout.MODE_FIXED);
         ;
            for (int i = 0; i < titleList.size(); i++) {
                tabLayout.addTab(tabLayout.newTab().setText(titleList.get(i)));

                }

        //将要展示的碎片添加进列表
        List<Fragment> fragmentList = new ArrayList<>();;
        fragmentList.add(new RecommendFragment());
        fragmentList.add(new FollowFragment());
        fragmentList.add(new MaFriendFragment());
        fragmentList.add(new LookForPerFragment());
        fragmentList.add(new MaPlayFragment());

        MyFragmentAdapter myFragmentAdapter = new MyFragmentAdapter(getChildFragmentManager(),fragmentList,titleList);
        viewPager.setAdapter(myFragmentAdapter);  //设置viewPager适配器
        tabLayout.setupWithViewPager(viewPager);  //将TabLayout和ViewPager关联起来
        return view;
}


}
